<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>jsonp实现跨域</title>
</head>

<body>
  <div id="msg"></div>


  <!-- <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.10.0/jquery.js"></script>
  <script>
    let url = 'http://localhost:3000/v1/web'
    $.ajax({
      method: 'GET',
      url,
      dataType: 'jsonp',
      success: res => console.log(res)
    })
  </script> -->
  <!-- <script>
    // jsonp调用的函数
    function fn(arg) {
      console.log(arg)
    }
  </script> -->
  <!-- 客户端需要传入回调的函数名称，并且还需要提前定义好 -->
  <!-- <script src="http://localhost:3000/v1/web?callback=fn"></script> -->

  <script>
    // 请求地址
    let url = 'http://localhost:3000/v1/web'
    const xhr = new XMLHttpRequest()
    xhr.onreadystatechange = () => {
      if (xhr.readyState == 4 && xhr.status == 200) {
        console.log(JSON.parse(xhr.responseText))
      }
    }
    xhr.open('GET', url, true)
    xhr.send(null)
  </script>

</body>

</html>